package com.atguigu.juc.sync;

/**
 * @author yanglin
 * @create 2024-02-01 16:32 星期四
 * description:
 */
public class LockBigDemo {

    /**
     * 锁粗化
     */
    
    static Object objectLock = new Object();

    public static void main(String[] args) {
        new Thread(() -> {
//            synchronized (objectLock){
//                System.out.println("hello LockBigDemo   111");
//            }
//            synchronized (objectLock){
//                System.out.println("hello LockBigDemo    222");
//            }
//            synchronized (objectLock){
//                System.out.println("hello LockBigDemo   333");
//            }
//            synchronized (objectLock){
//                System.out.println("hello LockBigDemo    444");
//            }
            
            //上述代码编译器会优化为：
            synchronized (objectLock){
                System.out.println("hello LockBigDemo   111");
                System.out.println("hello LockBigDemo    222");
                System.out.println("hello LockBigDemo   333");
                System.out.println("hello LockBigDemo    444");
            }
        }).start();
    }

}
